package com.ruoyi.evalution.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.evalution.domain.LabEvalutionTarget;
import com.ruoyi.evalution.service.ILabEvalutionTargetService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评试对象Controller
 * 
 * @author winner pan
 * @date 2022-04-15
 */
@RestController
@RequestMapping("/evalution/target")
public class LabEvalutionTargetController extends BaseController {
	@Autowired
	private ILabEvalutionTargetService labEvalutionTargetService;

	/**
	 * 查询评试对象列表
	 */
	//@PreAuthorize("@ss.hasPermi('evalution:target:list')")
	@GetMapping("/list")
	public TableDataInfo list(LabEvalutionTarget labEvalutionTarget) {
		startPage();
		List<LabEvalutionTarget> list = labEvalutionTargetService.selectLabEvalutionTargetList(labEvalutionTarget);
		return getDataTable(list);
	}
	
	@GetMapping("/reportlist")
	public TableDataInfo getHisReportlist(LabEvalutionTarget labEvalutionTarget) {
		startPage();
		labEvalutionTarget.setUserName(SecurityUtils.getUsername());
		List<LabEvalutionTarget> list = labEvalutionTargetService.selectReportHisList(labEvalutionTarget);
		return getDataTable(list);
	}
	
	@GetMapping("/markscorelist")
	public TableDataInfo markscorelist(LabEvalutionTarget labEvalutionTarget) {
		startPage();
		labEvalutionTarget.setMarkscoreUser(SecurityUtils.getUsername());
		List<LabEvalutionTarget> list = labEvalutionTargetService.selectMarkScoreList(labEvalutionTarget);
		return getDataTable(list);
	}

	/**
	 * 导出评试对象列表
	 */
	//@PreAuthorize("@ss.hasPermi('evalution:target:export')")
	@Log(title = "评试对象", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(LabEvalutionTarget labEvalutionTarget) {
		List<LabEvalutionTarget> list = labEvalutionTargetService.selectLabEvalutionTargetList(labEvalutionTarget);
		ExcelUtil<LabEvalutionTarget> util = new ExcelUtil<LabEvalutionTarget>(LabEvalutionTarget.class);
		return util.exportExcel(list, "target");
	}

	/**
	 * 获取评试对象详细信息
	 */
	//@PreAuthorize("@ss.hasPermi('evalution:target:query')")
	@GetMapping(value = "/{participatorId}")
	public AjaxResult getInfo(@PathVariable("participatorId") Long participatorId) {
		return AjaxResult.success(labEvalutionTargetService.selectLabEvalutionTargetById(participatorId));
	}
	
	@GetMapping(value = "/score/{participatorId}")
	public AjaxResult getScoreInfo(@PathVariable("participatorId") Long participatorId) {
		String userName = SecurityUtils.getUsername();
		return AjaxResult.success(labEvalutionTargetService.selectLabEvalutionTargetScoreById(participatorId, userName));
	}

	/**
	 * 新增评试对象
	 */
	//@PreAuthorize("@ss.hasPermi('evalution:target:add')")
	@Log(title = "评试对象", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabEvalutionTarget labEvalutionTarget) {
		return toAjax(labEvalutionTargetService.insertLabEvalutionTarget(labEvalutionTarget));
	}

	/**
	 * 修改评试对象
	 */
	//@PreAuthorize("@ss.hasPermi('evalution:target:edit')")
	@Log(title = "评试对象", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabEvalutionTarget labEvalutionTarget) {
		return toAjax(labEvalutionTargetService.updateLabEvalutionTarget(labEvalutionTarget));
	}
	@Log(title = "评试对象打分", businessType = BusinessType.UPDATE)
	@PutMapping("/score")
	public AjaxResult scoreRecord(@RequestBody LabEvalutionTarget labEvalutionTarget) {
		return toAjax(labEvalutionTargetService.scoreRecord(labEvalutionTarget));
	}

	@PostMapping("/updateScore")
	public AjaxResult updateScore(@RequestBody LabEvalutionTarget labEvalutionTarget) {
		return toAjax(labEvalutionTargetService.scoreRecord(labEvalutionTarget));
	}
	/**
	 * 删除评试对象
	 */
	//@PreAuthorize("@ss.hasPermi('evalution:target:remove')")
	@Log(title = "评试对象", businessType = BusinessType.DELETE)
	@DeleteMapping("/{participatorId}")
	public AjaxResult remove(@PathVariable Long participatorId) {
		return toAjax(labEvalutionTargetService.deleteLabEvalutionTargetById(participatorId));
	}
}
